<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" method="" id="form">
        <input type="text" name="" id="ipt">
        <button id="btn">点击查询</button>



        <script>
              //获取元素
        const oForm = document.getElementById('form');
        const oBtn = document.getElementById('btn')
        const oIpn = document.getElementById('ipt')
        //给表单绑定事件
        oForm.onsubmit = function(){
            //获取输入的值
            const userId = oIpn.value;
            //实例化
            const xhr  = new XMLHttpRequest();
            //打开路径
            // path 传参就是把参数以路径的形式写入
            xhr.open('GET', `/userInfo/${userId}?&_=${Date.now()}`,true);
            //发送
            xhr.send();
            //绑定事件
            xhr.onreadystatechange=function(){
                if(xhr.readyState ===4 &&(xhr.status >=200 && xhr.status <= 299)){
                    const data = JSON.parse(xhr.responseText)
                    console.log(data);
                }
            }
            return false 
        }
        </script>
    </form>
</body>
</html>